package br.edu.ufcg.p1.barzin.async;

import java.util.List;

import android.os.AsyncTask;
import br.edu.ufcg.p1.barzin.App;
import br.edu.ufcg.p1.barzin.event.EventBus;
import br.edu.ufcg.p1.barzin.event.PropagandasRecuperadasEvento;
import br.edu.ufcg.p1.barzin.model.Propaganda;
import br.edu.ufcg.p1.barzin.util.HTTPCalls;

public class PropagandasTask extends AsyncTask<Integer, Integer, Boolean> {

	@Override
	protected Boolean doInBackground(Integer... versaoCardapio) {

		List<Propaganda> propagandas = HTTPCalls.recuperaPropagandas();

		return App.environment().getDao().salvaPropagandas(propagandas);
	}
	
	@Override
	protected void onPostExecute(Boolean result) {
		if (result) {
			EventBus.getInstance().publica(new PropagandasRecuperadasEvento());
		}
	}

}
